# this was called from the Makefile in /, 
# and we just tell it what objects that he should make. 

BITS 	= 64

asm 	= boot/boot$(BITS).S boot/setup$(BITS).S 
asmobj 	= boot/boot$(BITS).S.o boot/setup$(BITS).S.o 
obj-i 	+= 

target: 

ifeq ($(D), )
	@echo "this should call from the Makefile in directory /, but not typing make in kernel/. :-(" >&2 
	@exit 1
endif
	@echo -n "-m$(BITS) " > .archcflags
	@echo -n "-I`pwd`/include " >> .archcflags
	@echo -n "-I`pwd`/include$(BITS) " >> .archcflags

# must be the first 
	@echo "`pwd`/init/head$(BITS).S.o" > $(PWD)/.objlist 

# $(PWD) is the / directory of kernel, e.g. /root/evx/
	@$(MAKE) -C $(PWD) D=$(shell pwd) obj-i="$(obj-i)"

vmevx.o: $(PWD)/.objlist 
	@$(MAKE) -C init/ BITS=$(BITS)
	@cat $(PWD)/.objlist | xargs $(LD) -o vmevx.o -T vmevx$(BITS).lds --no-relax 
	@echo "LD                vmevx.o"

vmevx.bin: vmevx.o
	@objcopy -S -R ".comment" -R ".eh_frame" -O binary vmevx.o vmevx.bin 


boot: 	vmevx.bin  
	@$(MAKE) -C boot/ BITS=$(BITS)


.PHONY clean:
	@$(MAKE) -C boot/ clean
	@$(MAKE) -C init/ clean


